package org.jcnc.staffingsystem.module;

import javafx.geometry.Pos;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.text.Text;

public class PasswordBox extends HBox {
    Text textTip = new Text();
    PasswordField passwordField;

    public PasswordBox(String t) {
        passwordField = new PasswordField();
        Region spacer = new Region();
        Text text = new Text(t);
        spacer.setPrefWidth(10);
        passwordField.setPrefWidth(200);
        this.setAlignment(Pos.CENTER);
        this.getChildren().addAll(text, spacer, passwordField, textTip);
    }

    // 新增的方法：验证密码是否符合要求
    public boolean validatePassword() {
        String password = passwordField.getText();
        if (password.isEmpty()) {
            textTip.setText("请输入密码");
            return false;
        } else if (password.length() < 8) {
            textTip.setText("密码长度至少为8位");
            return false;
        } else {
            textTip.setText("");
            return true;
        }
    }

    // 新增的方法：获取密码框中的内容
    public String getText() {
        return passwordField.getText();
    }

    // 新增的方法：设置密码框中的内容
    public void setPassword(String password) {
        passwordField.setText(password);
    }
}
